package com.dawn.module.cms.dal.mysql.article;


import com.dawn.framework.common.pojo.PageResult;
import com.dawn.framework.mybatis.core.mapper.BaseMapperX;
import com.dawn.framework.mybatis.core.query.LambdaQueryWrapperX;
import com.dawn.module.cms.controller.admin.article.vo.ArticlePageReqVO;
import com.dawn.module.cms.controller.app.article.vo.AppArticlePageReqVO;
import com.dawn.module.cms.dal.dataobject.article.CmsArticleDO;
import org.apache.ibatis.annotations.Mapper;

/**
 * 文章 Mapper
 *
 * @author yyh
 */
@Mapper
public interface CmsArticleMapper extends BaseMapperX<CmsArticleDO> {

    default PageResult<CmsArticleDO> selectPage(ArticlePageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<CmsArticleDO>()
                .eqIfPresent(CmsArticleDO::getTitle, reqVO.getTitle())
                .eqIfPresent(CmsArticleDO::getDescription, reqVO.getDescription())
                .eqIfPresent(CmsArticleDO::getTags, reqVO.getTags())
                .eqIfPresent(CmsArticleDO::getCategoryId, reqVO.getCategoryId())
                .eqIfPresent(CmsArticleDO::getCategoryKey, reqVO.getCategoryKey())
                .eqIfPresent(CmsArticleDO::getPublish, reqVO.getPublish())
                .eqIfPresent(CmsArticleDO::getTopping, reqVO.getTopping())
                .betweenIfPresent(CmsArticleDO::getPublishTime, reqVO.getPublishTime())
                .eqIfPresent(CmsArticleDO::getCoverImg, reqVO.getCoverImg())
                .eqIfPresent(CmsArticleDO::getViews, reqVO.getViews())
                .eqIfPresent(CmsArticleDO::getSource, reqVO.getSource())
                .eqIfPresent(CmsArticleDO::getPublishUser, reqVO.getPublishUser())
                .eqIfPresent(CmsArticleDO::getLinkUrl, reqVO.getLinkUrl())
                .eqIfPresent(CmsArticleDO::getStatus, reqVO.getStatus())
                .betweenIfPresent(CmsArticleDO::getCreateTime, reqVO.getCreateTime())
                .eqIfPresent(CmsArticleDO::getKeywords, reqVO.getKeywords())
                .eqIfPresent(CmsArticleDO::getAuthor, reqVO.getAuthor())
                .eqIfPresent(CmsArticleDO::getDemoType, reqVO.getDemoType())
                .eqIfPresent(CmsArticleDO::getDemoUrl, reqVO.getDemoUrl())
                .eqIfPresent(CmsArticleDO::getPictures, reqVO.getPictures())
                .eqIfPresent(CmsArticleDO::getFiles, reqVO.getFiles())
                .eqIfPresent(CmsArticleDO::getRecommend, reqVO.getRecommend())
                .eqIfPresent(CmsArticleDO::getSort, reqVO.getSort())
                .orderByDesc(CmsArticleDO::getSort).orderByDesc(CmsArticleDO::getUpdateTime));
    }


    default PageResult<CmsArticleDO> selectPage(AppArticlePageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<CmsArticleDO>()
                .eqIfPresent(CmsArticleDO::getTitle, reqVO.getTitle())
                .eqIfPresent(CmsArticleDO::getDescription, reqVO.getDescription())
                .eqIfPresent(CmsArticleDO::getTags, reqVO.getTags())
                .eqIfPresent(CmsArticleDO::getCategoryId, reqVO.getCategoryId())
                .eqIfPresent(CmsArticleDO::getCategoryKey, reqVO.getCategoryKey())
                .eqIfPresent(CmsArticleDO::getPublish, reqVO.getPublish())
                .eqIfPresent(CmsArticleDO::getTopping, reqVO.getTopping())
                .betweenIfPresent(CmsArticleDO::getPublishTime, reqVO.getPublishTime())
                .eqIfPresent(CmsArticleDO::getCoverImg, reqVO.getCoverImg())
                .eqIfPresent(CmsArticleDO::getViews, reqVO.getViews())
                .eqIfPresent(CmsArticleDO::getSource, reqVO.getSource())
                .eqIfPresent(CmsArticleDO::getPublishUser, reqVO.getPublishUser())
                .eqIfPresent(CmsArticleDO::getLinkUrl, reqVO.getLinkUrl())
                .eqIfPresent(CmsArticleDO::getStatus, reqVO.getStatus())
                .betweenIfPresent(CmsArticleDO::getCreateTime, reqVO.getCreateTime())
                .eqIfPresent(CmsArticleDO::getKeywords, reqVO.getKeywords())
                .eqIfPresent(CmsArticleDO::getAuthor, reqVO.getAuthor())
                .eqIfPresent(CmsArticleDO::getDemoType, reqVO.getDemoType())
                .eqIfPresent(CmsArticleDO::getDemoUrl, reqVO.getDemoUrl())
                .eqIfPresent(CmsArticleDO::getPictures, reqVO.getPictures())
                .eqIfPresent(CmsArticleDO::getFiles, reqVO.getFiles())
                .eqIfPresent(CmsArticleDO::getRecommend, reqVO.getRecommend())
                .eqIfPresent(CmsArticleDO::getSort, reqVO.getSort())
                .orderByDesc(CmsArticleDO::getSort).orderByDesc(CmsArticleDO::getUpdateTime));
    }

}